/**
 *
 * @author DnD Binary Source
 */
package Entities;

import AbstractClasses.Lista;
import java.io.Serializable;
import java.util.ArrayList;

public class BookList extends Lista implements Serializable{
    private static BookList bookList;
    
    private BookList(){
        elements = new ArrayList<Object>();
        bookList = this;
    }
    
    public static BookList getInstance(){
        if(bookList == null){
            bookList = new BookList();
        }
        return bookList;
    }
        
    @Override
    public void add(Object book){
        initializeList();
        if(book instanceof Book){
            this.elements.add((Book) book);
            Handler.updateBookList();
        }
        else{
             throw new UnsupportedOperationException("You can add only books here.");
        }
    }
    
    @Override
    public void remove(int position){
        this.elements.remove(position);
        Handler.updateBookList();
    }
    
    @Override
    public void updateItem(){
        Handler.updateBookList();
    }
    
    public void initializeList(){
        if(elements==null){
            this.elements = new ArrayList<Object>();
        }
    }
}
